﻿using System;
using System.Numerics;
using System.Threading.Tasks;

class Program
{
    static async Task Main(string[] args)
    {
        double a = 2.5;  // 1 < a < 10
        double b = 3.2;  // 1 < b < 10

        Console.WriteLine($"计算 {a}^58 + {b}^50");

        // 并行计算两个幂运算
        Task<double> task1 = CalculatePowerAsync(a, 58);
        Task<double> task2 = CalculatePowerAsync(b, 50);

        // 等待两个任务完成
        double result1 = await task1;
        double result2 = await task2;

        double finalResult = result1 + result2;

        Console.WriteLine($"\n计算结果:");
        Console.WriteLine($"{a}^58 = {result1:E}");
        Console.WriteLine($"{b}^50 = {result2:E}");
        Console.WriteLine($"总和 = {finalResult:E}");
        Console.WriteLine($"总和(精确) = {finalResult}");
    }

    static async Task<double> CalculatePowerAsync(double baseNumber, int exponent)
    {
        return await Task.Run(() =>
        {
            Console.WriteLine($"开始计算 {baseNumber}^{exponent}...");

            // 使用BigInteger处理大数，然后转换回double
            double result = 1.0;
            for (int i = 0; i < exponent; i++)
            {
                result *= baseNumber;

                // 模拟复杂计算（实际中大数计算需要时间）
                if (i % 10 == 0)
                {
                    Task.Delay(1).Wait(); // 短暂延迟，模拟计算时间
                }
            }

            Console.WriteLine($"完成计算 {baseNumber}^{exponent}");
            return result;
        });
    }
}